/************************************************************************
 * @file PluginDescriptionManager.h
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#ifndef PLUGINDESCRIPTIONMANAGER_H
#define PLUGINDESCRIPTIONMANAGER_H

#include <map>

using namespace std;

#include <QStringList>

#include <plugin/plugin_global.h>
#include <plugin/plugin/PluginDescription.h>

namespace antu
{
namespace plugin
{
class PLUGINSHARED_EXPORT PluginDescriptionManager
{
public:
    PluginDescriptionManager();

    ~PluginDescriptionManager();

    void init(const QString& applicationGroup, const QString& path);

    PluginDescriptionSharedPtr findDescription(const QString& code);

    vector<PluginDescriptionSharedPtr> findAll()
    {
        return this->m_oResolvedPluginDescriptions;
    }

    vector<PluginDescriptionSharedPtr> findDependentDescriptions(const QString& code);

    vector<PluginDescriptionSharedPtr> findRequiredDescriptions(const QString& code);

    vector<PluginDescriptionSharedPtr> findAllNeededDescriptions(const QStringList& codes);

    inline size_t descriptionCount() const
    {
        return this->m_oResolvedPluginDescriptions.size();
    }

    inline PluginDescriptionSharedPtr descriptionAt(size_t i)
    {
        Q_ASSERT(i >= 0 && i < this->m_oResolvedPluginDescriptions.size());
        return this->m_oResolvedPluginDescriptions.at(i);
    }

private:
    vector<PluginDescriptionSharedPtr> m_oResolvedPluginDescriptions;
    map<QString, PluginDescriptionSharedPtr> m_oSortedPluginDescriptions;
};
}
}


#endif // PLUGINDESCRIPTIONMANAGER_H
